package com.onluy.framework.data.util;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;

public class DataMap<K, V> extends HashMap<K, V>
  implements IData<K, V>
{
  public V get(Object name)
  {
    return super.get(name);
  }

  public V get(Object name, Object def)
  {
    Object value = get(name);
    return (V) (value == null ? def : value);
  }

  public String[] getNames()
  {
    String[] names = (String[])(String[])keySet().toArray(new String[0]);
    Arrays.sort(names);
    return names;
  }

  public String getString(String name)
  {
    Object value = get(name);
    return value == null ? null : value.toString();
  }

  public String getString(String name, String defaultValue)
  {
    return get(name, defaultValue).toString();
  }

  public int getInt(String name)
  {
    return getInt(name, 0);
  }

  public int getInt(String name, int defaultValue)
  {
    String value = getString(name, "");
    return "".equals(value) ? defaultValue : Integer.parseInt(value);
  }

  public double getDouble(String name)
  {
    return getDouble(name, 0.0D);
  }

  public double getDouble(String name, double defaultValue)
  {
    String value = getString(name, "");
    return "".equals(value) ? defaultValue : Double.parseDouble(value);
  }

  public boolean getBoolean(String name)
  {
    return getBoolean(name, false);
  }

  public boolean getBoolean(String name, boolean defaultValue)
  {
    String value = getString(name, "");
    return "".equals(value) ? defaultValue : Boolean.valueOf(value).booleanValue();
  }

  public BigDecimal getBigDecimal(String name)
  {
    return getBigDecimal(name, null);
  }

  public BigDecimal getBigDecimal(String name, BigDecimal defaultValue)
  {
    String value = getString(name, "");
    return "".equals(value) ? defaultValue : new BigDecimal(value);
  }
}